//
//  YSViewController.m
//  YSDownLoadManager
//
//  Created by kysonyangs on 11/20/2018.
//  Copyright (c) 2018 kysonyangs. All rights reserved.
//

#import "YSViewController.h"
#import "YSSearchBookWebVC.h"
#import <WebKit/WebKit.h>
#import "YSDownloadListernVC.h"

@interface YSViewController ()

@end

@implementation YSViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"下载" style:UIBarButtonItemStylePlain target:self action:@selector(showDownloadVC)];
}

- (void)showDownloadVC {
    [self.navigationController pushViewController:[YSDownloadListernVC new] animated:YES];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self deleteWebCache];
}

- (void)deleteWebCache {
    //allWebsiteDataTypes清除所有缓存
    NSSet *websiteDataTypes = [WKWebsiteDataStore allWebsiteDataTypes];
    
    NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0];
    
    [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:^{
        
    }];
}

- (IBAction)goWebButtonDidClick:(id)sender {
    YSSearchBookWebVC *searchBookVC = [[YSSearchBookWebVC alloc] init];
    [self.navigationController pushViewController:searchBookVC animated:YES];
}

@end
